using System;
namespace APP.HELPER.Utils.BarcodeLib
{
	internal class UPCSupplement5 : BarcodeCommon, IBarcode
	{
		private string[] EAN_CodeA = new string[]
		{
			"0001101",
			"0011001",
			"0010011",
			"0111101",
			"0100011",
			"0110001",
			"0101111",
			"0111011",
			"0110111",
			"0001011"
		};
		private string[] EAN_CodeB = new string[]
		{
			"0100111",
			"0110011",
			"0011011",
			"0100001",
			"0011101",
			"0111001",
			"0000101",
			"0010001",
			"0001001",
			"0010111"
		};
		private string[] UPC_SUPP_5 = new string[]
		{
			"bbaaa",
			"babaa",
			"baaba",
			"baaab",
			"abbaa",
			"aabba",
			"aaabb",
			"ababa",
			"abaab",
			"aabab"
		};
		public string Encoded_Value
		{
			get
			{
				return this.Encode_UPCSupplemental_5();
			}
		}
		public UPCSupplement5(string input)
		{
			this.Raw_Data = input;
		}
		private string Encode_UPCSupplemental_5()
		{
			if (this.Raw_Data.Length != 5)
			{
				throw new Exception("EUPC-SUP5-1: Invalid data length. (Length = 5 required).");
			}
			if (!BarcodeEdit.CheckNumericOnly(this.Raw_Data))
			{
				throw new Exception("EUPCA-2: Numeric Data Only");
			}
			int num = 0;
			int num2 = 0;
			for (int i = 0; i <= 4; i += 2)
			{
				num2 += int.Parse(this.Raw_Data.Substring(i, 1)) * 3;
			}
			for (int i = 1; i < 4; i += 2)
			{
				num += int.Parse(this.Raw_Data.Substring(i, 1)) * 9;
			}
			int num3 = num + num2;
			int num4 = num3 % 10;
			string text = this.UPC_SUPP_5[num4];
			string text2 = "";
			int num5 = 0;
			string text3 = text;
			for (int j = 0; j < text3.Length; j++)
			{
				char c = text3[j];
				if (num5 == 0)
				{
					text2 += "1011";
				}
				else
				{
					text2 += "01";
				}
				if (c == 'a')
				{
					text2 += this.EAN_CodeA[int.Parse(this.Raw_Data[num5].ToString())];
				}
				else
				{
					if (c == 'b')
					{
						text2 += this.EAN_CodeB[int.Parse(this.Raw_Data[num5].ToString())];
					}
				}
				num5++;
			}
			return text2;
		}
	}
}
